package com.testing.class14;

import com.testing.DriverSelf.HttpDriver;
import com.testing.inter.InterKeyWord;

/**
 * @Classname KwCookieTest
 * @Description 类型说明
 * @Date 2022/11/4 21:20
 * @Created by 特斯汀Roy
 */
public class KwCookieTest {

    public static void main(String[] args) {
        InterKeyWord inter=new InterKeyWord();
        inter.saveParam("url","http://localhost:9090/user");

        inter.testPostUrl("{url}/login","username=roy&password=123456");
        inter.assertJsonContainsValue("$.msg","登录成功");

        inter.testGet("{url}/getUser");
        inter.assertJsonContainsValue("$.msg","查询成功");

        inter.notUseCookie();
        inter.testGet("{url}/getUser");
        inter.assertJsonContainsValue("$.msg","不能查询");

        inter.useCookie();
        inter.testGet("{url}/getUser");
        inter.assertJsonContainsValue("$.msg","查询成功");
    }




    public static void driverTest(String[] args) {
        HttpDriver driver=new HttpDriver();
        //先登录，然后获取用户信息
        String login = driver.doPostUrl("http://localhost:9090/user/login", "username=roy&password=123456");

        String firstGet = driver.doGet("http://localhost:9090/user/getUser");
        System.out.println("登录后直接查询"+firstGet);
        //不带cookie获取用户信息，返回结果应该是不能查询
        driver.notUseCookie();
        String noCookieGet = driver.doGet("http://localhost:9090/user/getUser");
        System.out.println("不带cookie查询"+noCookieGet);
        //重新带上cookie之后再进行请求，查询成功

        driver.useCookie();
        String useCookieGet = driver.doGet("http://localhost:9090/user/getUser");
        System.out.println("重新戴上cookie查询"+useCookieGet);
    }
}
